<!-- 头部开始 -->
<%- include templates/_meta_top.ejs %>
<!-- 头部结束 -->
    <!-- Web Goobal Style-->
    <link href="/css/backend/css/goobal.css" rel="stylesheet">
    <!-- Page Index Style-->
  </head>

  <body class="nav-md">
    <div class="alert alert-success" role="alert">
        <strong><%- messages() %></strong>
    </div>
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
          <div class="left_col scroll-view">
            <div class="navbar nav_title" style="border: 0;">
              <a href="index.html" class="site_title"><i class="fa  fa-globe"></i> <span style="margin-left:10px;">海&nbsp;量&nbsp;通</span></a>
            </div>
            <div class="clearfix"></div>
            <br/>
            <!-- 侧栏开始 -->
            <%- include templates/_sidebar.ejs %>
            <!-- 侧栏结束 -->
          </div>
        </div>
        <!-- 头部导航开始 -->
        <%- include templates/_topNav.ejs %>
        <!-- 头部导航结束 -->

        <!-- 内容开始 -->
        <div class="right_col" role="main">
            <!-- top title -->
<!--             <div class="x_title">
              <h2>新增文章</h2>
              <div class="clearfix"></div>
            </div>
            <div class="clearfix"></div -->

            <!-- tongji -->
            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2><%= title %></h2>
                    <h2><%= post.title %></h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                      <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                        <ul class="dropdown-menu" role="menu">
                          <li><a href="#">Settings 1</a>
                          </li>
                          <li><a href="#">Settings 2</a>
                          </li>
                        </ul>
                      </li>
                      <li><a class="close-link"><i class="fa fa-close"></i></a>
                      </li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <br>
                    <form id="addArticles" method="post" action="<%= action %>" class="form-horizontal form-label-left" novalidate="">

                      <div class="form-group">
                        <label class="control-label col-md-1 col-sm-1 col-xs-12" for="first-name">文章标题<span class="required">*</span>
                        </label>
                        <div class="col-md-9 col-sm-9 col-xs-12">
                          <input type="text" name="title" required="required" class="form-control col-md-7 col-xs-12" value="<%= post.title%>">
                        </div>
                      </div>

                      <div class="form-group">
                        <label class="control-label col-md-1 col-sm-1 col-xs-12" for="first-name">文章分类<span class="required">*</span>
                        </label>
                        <div class="col-md-9 col-sm-9 col-xs-12">
                            <select id="heard" name="category" class="form-control" required="">
                              <option value="" >选择分类</option>
                              <% locals.categories.forEach(function (category){ %>
                                  <option value="<%= category._id %>" selected="<%= (category.name === post.category.name) ? "selected" : false %>"><%= category.name %></option>
                              <% }) %>
                            </select>
                        </div>
                      </div>


                      <div class="form-group">
                        <label class="control-label col-md-1 col-sm-1 col-xs-12" for="first-name">文章内容<span class="required">*</span>
                        </label>
                        <div class="col-md-9 col-sm-9 col-xs-12">
                            <textarea id="js-article-body" class="form-control" name="body" value="<%= post.body %>"><%= post.body %></textarea>
                        </div>
                      </div>

                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-1">
                          <button type="submit" class="btn btn-primary"><%= post ? '保存修改' : '发布文章' %></button>
                        </div>
                      </div>

                    </form>
                  </div>
                </div>
              </div>
            </div>

        </div>
        <!-- 内容结束 -->

    <!-- 底部开始 -->
    <%- include templates/_meta_bottom.ejs %>
    <!-- 底部结束 -->
    <script src="/js/ckeditor/ckeditor.js"></script>
<script>
      $(document).ready(function() {
        CKEDITOR.replace('js-article-body');
        function initToolbarBootstrapBindings() {
          var fonts = ['Serif', 'Sans', 'Arial', 'Arial Black', 'Courier',
              'Courier New', 'Comic Sans MS', 'Helvetica', 'Impact', 'Lucida Grande', 'Lucida Sans', 'Tahoma', 'Times',
              'Times New Roman', 'Verdana'
            ],
            fontTarget = $('[title=Font]').siblings('.dropdown-menu');
          $.each(fonts, function(idx, fontName) {
            fontTarget.append($('<li><a data-edit="fontName ' + fontName + '" style="font-family:\'' + fontName + '\'">' + fontName + '</a></li>'));
          });
          $('a[title]').tooltip({
            container: 'body'
          });
          $('.dropdown-menu input').click(function() {
              return false;
            })
            .change(function() {
              $(this).parent('.dropdown-menu').siblings('.dropdown-toggle').dropdown('toggle');
            })
            .keydown('esc', function() {
              this.value = '';
              $(this).change();
            });

          $('[data-role=magic-overlay]').each(function() {
            var overlay = $(this),
              target = $(overlay.data('target'));
            overlay.css('opacity', 0).css('position', 'absolute').offset(target.offset()).width(target.outerWidth()).height(target.outerHeight());
          });

          if ("onwebkitspeechchange" in document.createElement("input")) {
            var editorOffset = $('#editor').offset();

            $('.voiceBtn').css('position', 'absolute').offset({
              top: editorOffset.top,
              left: editorOffset.left + $('#editor').innerWidth() - 35
            });
          } else {
            $('.voiceBtn').hide();
          }
        }

        function showErrorAlert(reason, detail) {
          var msg = '';
          if (reason === 'unsupported-file-type') {
            msg = "Unsupported format " + detail;
          } else {
            console.log("error uploading file", reason, detail);
          }
          $('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>' +
            '<strong>File upload error</strong> ' + msg + ' </div>').prependTo('#alerts');
        }

        initToolbarBootstrapBindings();

        $('#editor').wysiwyg({
          fileUploadError: showErrorAlert
        });

        window.prettyPrint;
        prettyPrint();
      });
    </script>
    <script>
      function logout(){

        bootbox.dialog({
          title : "提示信息",
          message : "<p>退出系统 ？</p>",
          buttons : {
              "success" : {
                  "label" : "<i class='icon-ok'></i> 确认",
                  "className" : "btn-sm btn-success",
              },
              "cancel" : {
                  "label" : "<i class='icon-info'></i> 取消",
                  "className" : "btn-sm btn-danger",
                  "callback" : function() { }
              }
          }
        })
      }
    </script>
  </body>
</html>
